package com.luchi.preprocess;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.luchi.svm.Constants;

public class ReadStopWords {
	private String stop_word_path=Constants.STOP_WORDS_PATH;
	private List<String> stopWords=new ArrayList<String>();
	public List getStopwords(){
		if(stopWords.size()==0){
			return getStopwordsFromFile();
		}else{
			return stopWords;
		}
	}
	private List getStopwordsFromFile(){
		FileReader fr=null;
		BufferedReader reader=null;
		try {
			File file =new File(stop_word_path);
			fr=new FileReader(file);
			reader=new BufferedReader(fr);
			String str="";
			while((str=reader.readLine())!=null){
				stopWords.add(str);
			}
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				reader.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return stopWords;
		
	}
}
